from lxml import etree
#这是一个xmldemo脚本

xml="""
    <book>
        <id>1</id>
        <name>文学</name>
        <price>34.0</price>
        <nick>--</nick>
        <author>
            <nick>莫言</nick>
            <nick>余华</nick>
            <nick>史铁生</nick>
            <nick>贾平凹</nick>
            <div>
                <nick>村上春树</nick>
            </div>
            <span>
                <nick>太宰治</nick>
            </span>
        </author>
    </book>
"""

tree=etree.XML(xml)
#指定节点拿取文本
nameResult=tree.xpath("/book/name/text()")
#拿到兄弟节点文本
nickResult=tree.xpath("/book/author/nick/text()")
#拿到author下所有nick文本
nickResult2=tree.xpath("/book/author//nick/text()")
#通配符拿取
nickResult3=tree.xpath("/book/author/*/nick/text()")
print(nickResult2)


